package command;

import model.impl.TicketImpl;
import DTO.TicketDTO;

import com.gmail.at.vssabinin.train_transport_system_part1.Protocol;
import com.gmail.at.vssabinin.train_transport_system_part1.ReceivedData;

/**
 * Class represents command interface;
 * It removes passenger from train according to information received from 
 * administer client. After operation if it was successful it sends back OK 
 * to administer client, else it sends NO.
 */
public class AdminRemovePassengerFromTrain implements Command {

private Protocol protocol = new Protocol();
	
	public void execute(ReceivedData recived) {
		Protocol.Message message = this.protocol.decodeMessage(recived.data);
		TicketDTO ticket =  (TicketDTO) message.getObject();
		model.Ticket ticketImpl = new TicketImpl();
		if (ticketImpl.sellTicket(ticket)) {
			Protocol.Message answer = this.protocol.new Message("ok", null);
			recived.server.send(recived.socket, this.protocol.createMessage(answer));
		} else {
			Protocol.Message answer = this.protocol.new Message("no", null);
			recived.server.send(recived.socket, this.protocol.createMessage(answer));
		}		
	}
}
